﻿using System;
using System.Globalization;

namespace EasyBackup.Utils
{
    static class Period
    {
        public static int GetWeekOfMonth(DateTime date)
        {
            DateTime beginningOfMonth = new DateTime(date.Year, date.Month, 1);

            while (date.Date.AddDays(1).DayOfWeek != CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek)
            {
                date = date.AddDays(1);
            }

            return (int)Math.Truncate(date.Subtract(beginningOfMonth).TotalDays / 7f) + 1;
        }

        public static bool IsEvenWeek(DateTime date)
        {
            return (GetWeekOfMonth(date) % 2) == 0;
        }
    }
}
